package com.sy.service.Impl;

import com.sy.entity.CCollection;
import com.sy.entity.Cartoon;
import com.sy.entity.Media;
import com.sy.entity.VCollection;
import com.sy.mapper.CartoonMapper;
import com.sy.mapper.CollectionMapper;
import com.sy.mapper.MediaMapper;
import com.sy.service.CollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author King
 * @Date 2021/1/18 09:36
 */
@Service
public class CollectionServiceImpl implements CollectionService {

    @Autowired
    private CollectionMapper mapper;

    @Autowired
    private CartoonMapper cmapper;

    @Autowired
    private MediaMapper mediaMapper;

    @Override
    public List<Cartoon> getCartCollection(Integer userId) {
        List<CCollection> cCollections = mapper.selectByCartoon(userId);
        Set<Integer> set = new HashSet<>();
        for (CCollection c : cCollections){
            set.add(c.getcId());
        }
        System.out.println(set);
        List<Cartoon> cartoons = cmapper.selectCartoonTen(set);
        return cartoons;
    }

    @Override
    public List<Media> getMediaCollection(Integer userId) {
        List<VCollection> vCollections = mapper.selectByVideo(userId);
        List<Integer> list = new ArrayList<>();
        for (VCollection v : vCollections){
            list.add(v.getvId());
        }
        System.out.println(list);
        List<Media> media = mediaMapper.selectListId(list);
        return media;
    }


    @Override
    public int delCollectionCartoon(Integer userId, Integer cId) {
        return mapper.delCollectionCartoon(userId,cId);
    }

    @Override
    public int delCollectionMedia(Integer userId, Integer cId) {
        return mapper.delCollectionMedia(userId,cId);
    }

    @Override
    public int insertCartoonCollection(Integer userId, Integer cId) {
        return mapper.insertCartoonCollection(userId,cId);
    }

    @Override
    public int insertMediaCollection(Integer userId, Integer cId) {
        return mapper.insertMediaCollection(userId,cId);
    }

    @Override
    public CCollection selectCartoonCollection(Integer userId, Integer cId) {
        return mapper.selectCartoonCollection(userId,cId);
    }

    @Override
    public VCollection selectMediaCollection(Integer userId, Integer cId) {
        return mapper.selectMediaCollection(userId,cId);
    }


}
